package com.oa.lms.apps.business.user.impl;

import java.util.List;

import com.oa.lms.apps.business.user.IPostInfoService;
import com.oa.lms.apps.business.user.ISectionInfoService;
import com.oa.lms.apps.constants.IDEDStatus;
import com.oa.lms.apps.dao.user.IPostInfoDao;
import com.oa.lms.apps.entity.user.PostInfoValue;

public class PostInfoServiceImpl implements IPostInfoService {
	
	private IPostInfoDao postInfoDao;
	
	private ISectionInfoService sectionInfoService;
	
	private PostInfoValue postInfoValue;
	
	@Override
	public Integer add(String postName, Integer sectionId) {
		postInfoValue.setPostName(postName);
		postInfoValue.setSectionInfo(sectionInfoService.queryBySectionId(sectionId));
		postInfoValue.setStatus(IDEDStatus.ENABLE);
		return postInfoDao.add(postInfoValue);
	}

	@Override
	public void modify(Integer postId, String postName, Integer sectionId) {
		postInfoValue = this.queryByPostId(postId);
		postInfoValue.setPostName(postName);
		postInfoValue.setSectionInfo(sectionInfoService.queryBySectionId(sectionId));
		postInfoDao.modify(postInfoValue);
	}

	@Override
	public void delete(Integer postId) {
		postInfoValue = this.queryByPostId(postId);
		postInfoValue.setStatus(IDEDStatus.DELETE);
		postInfoDao.modify(postInfoValue);
		
	}

	@Override
	public void toDisable(Integer postId) {
		postInfoValue = this.queryByPostId(postId);
		postInfoValue.setStatus(IDEDStatus.DISABLE);
		postInfoDao.modify(postInfoValue);
		
	}

	@Override
	public void toEnable(Integer postId) {
		postInfoValue = this.queryByPostId(postId);
		postInfoValue.setStatus(IDEDStatus.ENABLE);
		postInfoDao.modify(postInfoValue);
		
	}

	@Override
	public PostInfoValue queryByPostId(Integer postId) {
		return postInfoDao.queryByPostId(postId);
	}

	@Override
	public List<PostInfoValue> queryPostInfo(String postName,
			Integer sectionId, Integer status) {
		if(postName != null)
			postInfoValue.setPostName(postName);
		if(sectionId != null)
			postInfoValue.setSectionInfo(sectionInfoService.queryBySectionId(sectionId));
		if(status != null)
			postInfoValue.setStatus(status);
		return postInfoDao.queryPostInfo(postInfoValue);
	}

	//Getter and Setter

	public IPostInfoDao getPostInfoDao() {
		return postInfoDao;
	}

	public void setPostInfoDao(IPostInfoDao postInfoDao) {
		this.postInfoDao = postInfoDao;
	}

	public ISectionInfoService getSectionInfoService() {
		return sectionInfoService;
	}

	public void setSectionInfoService(ISectionInfoService sectionInfoService) {
		this.sectionInfoService = sectionInfoService;
	}

	public PostInfoValue getPostInfoValue() {
		return postInfoValue;
	}

	public void setPostInfoValue(PostInfoValue postInfoValue) {
		this.postInfoValue = postInfoValue;
	}

}
